<%@page import="net.vinote.smart.platform.module.database.bo.DBQuery"%>
<%@page import="net.vinote.smart.platform.module.database.bo.BizObject"%>
<%@page import="net.vinote.smart.platform.service.dw.html.UIEvent"%>
<%@page import="net.vinote.smart.platform.service.awe.layout.easyui.Icon"%>
<%@page import="net.vinote.smart.platform.service.awe.layout.easyui.Button"%>
<%@page import="net.vinote.smart.platform.module.database.DBManagerFactory"%>
<%@page import="java.util.List"%>
<%@page import="net.vinote.smart.platform.module.database.DBManager"%>
<%@page import="net.vinote.smart.platform.comm.PlatformConst"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%
	List<BizObject>	list=null;
%>
<%@include file="/comm/tree_begin.jsp"%>
<%
	String objectType = request.getParameter("ObjectType");
		String objectID = request.getParameter("ObjectID");
		tree = treeUI.getTreeBySQLCode("RoleInfoSelect",
		PlatformConst.TreeProperty.SHOW_CHECKBOX);

		//生成操作按钮
		Button linkBtn = new Button(Button.BUTTON_TYPE_LINK);
		linkBtn.addContent("确定");
		linkBtn.setIcon(Icon.ADD);
		linkBtn.addEvent(UIEvent.ON_CLICK, "doSure()");
		out.print(linkBtn.getHtml());
		linkBtn.setIcon(Icon.DEL);
		linkBtn.setContent("关闭");
		linkBtn.addEvent(UIEvent.ON_CLICK, "self.close();");
		out.print(linkBtn.getHtml());
		
		//加载当前对象已具备角色
		DBManager bm = DBManagerFactory.getInstance("role_object_rela");
		DBQuery query = bm.createQuery(new String[] { "roleID" },
		"objectID=? and objectType=?").setParamVal(objectID,
		objectType);
		list = query.getResultList();
%>
<script>
	Key.registerKeyBom("ctrl+s", function() {
		doSure();
	});

	function doSure() {
		var ids = [];
		var rows = $('#RoleInfoSelect').tree('getChecked');
		for ( var i = 0; i < rows.length; i++) {
			if(rows[i].attributes.ISTRUNK=='1'){
				continue;
			}
			ids.push(rows[i].attributes.ROLEID);
		}
		var sReturn=RunJavaMethodTrans("platform.roleObjectRelaAction","setRoleObjectRela",{roles:ids.join(','),objectID:'<%=objectID%>',objectType:'<%=objectType%>'});
		if("<%=PlatformConst.SUCCESS%>" == sReturn) {
			alert("保存成功!");
		} else {
			alert(sReturn);
		}
		//self.returnValue=ids;
		//self.close();
	}
</script>
<%@include file="/comm/tree_end.jsp"%>
<% if(list!=null&&list.size()>0) {%>
<script>
$(function() {
	/**
	 *页面加载完后勾选当前用户已具备的角色选项
	 */
	$('#RoleInfoSelect').tree({
			onLoadSuccess : function(node, data) {
							<% for(BizObject bo:list){%>
								node = $('#RoleInfoSelect').tree('find',<%=bo.getAttribute("roleID")%>);
								if(node!=null){
								 	$('#RoleInfoSelect').tree('check', node.target);
								}
							<%}%>
			}
	});
});
</script>
<%}%>